import { Request, Response } from 'express';

const users = [
  {
    account: '0xfc97a1a683fb0108299d5725bc9d72899c9a86b4',
    username: 'ganyu',
  },
  {
    account: '0x4671bba62a82d9c7c88b13f02d1ccd7e1fa2d1d8',
    username: 'lalala',
  },
];

const account = {
  address: '0xfc97a1a683fb0108299d5725bc9d72899c9a86b4',
  user: {
    username: 'ganyu',
    avatar:
      'https://gw.alipayobjects.com/zos/antfincdn/XAosXuNZyF/BiazfanxmamNRoxxVxka.png',
  },
};

const account2 = {
  address: '0x4671BbA62a82D9c7C88B13F02D1cCd7e1fA2D1d8',
  user: {
    username: 'lalala',
    avatar:
      'https://gw.alipayobjects.com/zos/antfincdn/XAosXuNZyF/BiazfanxmamNRoxxVxka.png',
  },
};

export default {
  // 支持值为 Object 和 Array
  'GET /api/currentUser': (req: Request, res: Response) => {
    const { account } = req.query;
    let user = {};
    for (let i = 0; i < users.length; i++) {
      if (users[i].account === account) {
        user = users[i];
      }
    }

    res.send({
      success: true,
      data: user,
    });
  },
  'GET /api/account/0xfc97a1a683fb0108299d5725bc9d72899c9a86b4': (
    req: Request,
    res: Response,
  ) => {
    res.send({
      success: true,
      data: account,
    });
  },
  'GET /api/account/0x4671bba62a82d9c7c88b13f02d1ccd7e1fa2d1d8': (
    req: Request,
    res: Response,
  ) => {
    res.send({
      success: true,
      data: account2,
    });
  },
};
